#include <bits/stdc++.h>

using namespace std;

struct node
{
    int v;
    int cnt;
    node *next[2];
    node(int a)
    {
        v = a, cnt = -1;
    }
};

struct edge{
    int v, w;
};

map<int, vector<edge>> G;

int m, n, ans;
unsigned int s[1000001];
bool vis[1000001];

void dfs(int p, int l = 0){
    if (vis[p])
        return;
    s[p] = l;
    vis[p] = true;
    for (auto i : G[p])
        dfs(i.v, l ^ i.w);
}

void dfs2(node* p1, node* p2 = nullptr){
    if (p2 == nullptr){
        if (p1->next[0] && p1->next[1])
            dfs2(p1->next[0], p1->next[1]);
        else if (p1->next[0])
            dfs2(p1->next[0], p1->next[0]);
        else if (p1->next[1])
            dfs2(p1->next[1], p1->next[1]);
        return;
    }
    if (p1->cnt != -1){
        ans = max(ans, p1->cnt ^ p2->cnt);
        return;
    }
    if (p1->next[0] && p2->next[1])
        dfs2(p1->next[0], p2->next[1]);
    else if (p1->next[0] && p2->next[0])
        dfs2(p1->next[0], p2->next[0]);
    if (p1->next[1] && p2->next[0])
        dfs2(p1->next[1], p2->next[0]);
    else if (p1->next[1] && p2->next[1])
        dfs2(p1->next[1], p2->next[1]);
    
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    cin >> n;
    int u, v, w;
    for (int i = 1; i < n; i++){
        cin >> u >> v >> w;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    dfs(1);
    node *tree = new node(101);
    node *p = tree;
    for (int i = 1; i <= n; i++)
    {
        p = tree;
        for (int j = 30; j >= 0; j--)
            if (p->next[(s[i] >> j) & 1])
                p = p->next[(s[i] >> j) & 1];
            else
                p->next[(s[i] >> j) & 1] = new node(j), p = p->next[(s[i] >> j) & 1];
        p->cnt = s[i];
    }
    dfs2(tree);
    cout << ans << endl;
    return 0;
}
